/** 
 * A simple class for 
 * making a healthbar
 * and drawing it.
 * 
 * 
 * @author of Class: Andrew
 * @author of Functions: Maryam,David,Peak,Andrew
 * LAST UPDATED - 2/4/12 ANDREW
 */

public class HealthBar{
    
    // Private x Location
    private double x;
    
    // y location
    private double y;
    
    // the hearts
    private SimpleObject heart1;
    private SimpleObject heart2;
    private SimpleObject heart3;
    private SimpleObject heart4;
    private SimpleObject heart5;
    
    // the list of hearts
    SimpleObject[] life;
    
    // x and y position are inputs
    public HealthBar(double xi,double yi) {
        this.x = xi;
        this.y = yi;
        // create pictures around these input x and y values
        this.heart1 = JGE.newObject(x+40, y + 50, "heart.png");
        this.heart2 = JGE.newObject(x+10, y + 50, "heart.png");
        this.heart3 = JGE.newObject(x-20, y + 50, "heart.png");
        this.heart4 = JGE.newObject(x-50, y + 50, "heart.png");
        this.heart5 = JGE.newObject(x-80, y + 50, "heart.png");
    
        this.life = new SimpleObject[] {heart1,heart2,heart3,heart4,heart5};
        
    }
    
    // draw all the hearts, but only up to a certain number (tanks health)
    public void draw(int health) {
        for(int i = 0; i<health;i++) {
            life[i].draw();
        }
    }
    // resets the hearts
    public void update() {
    this.heart1 = JGE.newObject(x+40, y + 50, "heart.png");
    this.heart2 = JGE.newObject(x+10, y + 50, "heart.png");
    this.heart3 = JGE.newObject(x-20, y + 50, "heart.png");
    this.heart4 = JGE.newObject(x-50, y + 50, "heart.png");
    this.heart5 = JGE.newObject(x-80, y + 50, "heart.png");
    
    this.life = new SimpleObject[] {heart1,heart2,heart3,heart4,heart5};
        
    }
}